home *** CD-ROM | disk | FTP | other *** search
- unit UObj; {Quick Pascal Version} {90/01/10}
- {
- This unit contains the TObj class and was written to:
-
- 1) provide a "better" base object for Turbo Pascal programmers
- 2) enhance portability between Object Pascal and Turbo Pascal (MS/DOS)
- 3) provide the standard base object to Quick Pascal programmers
-
- Author: Mike Babulic Compuserve: 72307,314
- 3827 Charleswood Dr. N.W.
- Calgary, Alberta
- Canada
- T2L 2C7
- }
- interface
-
- type
- TObj = object
- function Clone: Pointer;
- {Copies SELF and returns a pointer to the copy
- Can override to copy objects referred to by
- fields of SELF}
- procedure Free;
- {Frees SELF from the heap.
- Can override to free objects referred to by
- fields of SELF}
- function ShallowClone: Pointer;
- {Low-level copy; should not be overridden
- except in very unusual cases}
- procedure ShallowFree;
- {Low-level method for freeing an object.
- Should not be overridden
- except in very unusual cases}
- function Bytes:Longint;
- {Returns the number of bytes in SELF}
- function TypeOf:Pointer;
- {Returns TypeOf(SELF)}
- end;
-
- TObject = TObj; {For compatability with Object Pascal programs}
-
- implementation
-
- type
-
- pClass = ^Class;
- Class = record
- IsThisParentOrMethodsOrSomethingElse : pClass;
- SizeOf : Word;
- end;
-
- pObject = ^rObject;
- rObject = record
- tag : pClass;
- data: integer;
- end;
-
- function TObject.ShallowClone: Pointer;
- var t:Pointer;
- begin
- t := nil;
- GetMem(t,SELF.Bytes);
- Move(pointer(self)^,t^,SELF.Bytes);
- ShallowClone := t;
- end;
-
- procedure TObject.ShallowFree;
- var t:Pointer;
- begin
- t := SELF;
- FreeMem(t,SELF.Bytes);
- end;
-
- function TObject.Clone: Pointer;
- begin
- Clone := SELF.ShallowClone;
- end;
-
- procedure TObject.Free;
- begin
- SELF.ShallowFree;
- end;
-
- function TObject.Bytes:Longint;
- begin
- Bytes := pObject(SELF)^.tag^.SizeOf;
- end;
-
- function TObject.TypeOf:Pointer;
- begin
- TypeOf := pObject(SELF)^.tag;
- end;
-
- end.